home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 07 - 1991 / 07.11 Nov 91 / TPose Source / UCharacterDialog.inc1.p < prev    next >
Encoding:
Text File  |  1991-05-23  |  43.5 KB  |  1,767 lines  |  [TEXT/MPS ]

  1. {*******************************************************************************
  2. UCharacterDialog.inc1.p
  3. *******************************************************************************}
  4.  
  5. USES
  6.     { • Implementation use }
  7.     Fonts,
  8.     Packages,
  9.     Picker,                    { TColorDialogCmd }
  10.     Resources,
  11.     ToolUtils;                { TColorDialogCmd }
  12.  
  13. TYPE
  14.     FondHandle            = ^FondPointer;
  15.     FondPointer         = ^FondRecord;
  16.     FondRecord            = RECORD
  17.         familyStuff:        FamRec;
  18.         noOfFonts:            INTEGER;
  19.         fontStuff:            ARRAY [0..1000] OF RECORD
  20.                             size:                INTEGER;
  21.                             style:                INTEGER;
  22.                             resID:                INTEGER;
  23.                               END;
  24.         END;
  25.  
  26. {###############################################################################
  27. Unit Initialization
  28. ###############################################################################}
  29.  
  30. {——————————————————————————————————————————————————————————————————————————————}
  31. {$S AInit}    
  32.     
  33. PROCEDURE InitUCharacterDialog;
  34.     VAR
  35.         dummy:            BOOLEAN;
  36.     
  37.     BEGIN
  38.     IF gDeadStripSuppression
  39.     THEN
  40.         BEGIN
  41.         { list the views instantiated via resource templates below }
  42.         dummy := Member(TObject(NIL), TCharDialogView);
  43.         dummy := Member(TObject(NIL), TFaceCluster);
  44.         dummy := Member(TObject(NIL), TFontListView);
  45.         dummy := Member(TObject(NIL), TJustifyCluster);
  46.         dummy := Member(TObject(NIL), TSampleText);
  47.         dummy := Member(TObject(NIL), TSetCluster);
  48.         dummy := Member(TObject(NIL), TSizeCluster);
  49.         dummy := Member(TObject(NIL), TSizeListView);
  50.         dummy := Member(TObject(NIL), TSizeText);
  51.         dummy := Member(TObject(NIL), TSpaceCluster);
  52.         dummy := Member(TObject(NIL), TStyleCluster);
  53.         dummy := Member(TObject(NIL), TValueCheckBox);
  54.         dummy := Member(TObject(NIL), TValueRadio);
  55.         dummy := Member(TObject(NIL), TValueRadioCluster);
  56.         END;  { if gDeadStripSuppression }
  57.     END;  { InitUCharacterDialog }
  58.  
  59.  
  60. {###############################################################################
  61. Utility Routines
  62. ###############################################################################}
  63.     
  64. {——————————————————————————————————————————————————————————————————————————————}
  65. {$ AUtil}
  66.  
  67. FUNCTION  SameRGBColor(color1, color2: RGBColor): BOOLEAN;
  68.     BEGIN
  69.     SameRGBColor := (color1.red   = color2.red)   &
  70.                     (color1.green = color2.green) &
  71.                     (color1.blue  = color2.blue);
  72.     END;  { SameRGBColor }
  73.     
  74. {——————————————————————————————————————————————————————————————————————————————}
  75. {$ AUtil}
  76.  
  77. FUNCTION  SameTextStyle(style1, style2: TextStyle): BOOLEAN;
  78.     BEGIN
  79.     SameTextStyle := (style1.tsFont = style2.tsFont) &
  80.                      (style1.tsFace = style2.tsFace) &
  81.                      (style1.tsSize = style2.tsSize) &
  82.                      SameRGBColor(style1.tsColor, style2.tsColor);
  83.     END;  { SameTextStyle }
  84.     
  85. {——————————————————————————————————————————————————————————————————————————————}
  86. {$ AUtil}
  87.  
  88. { AffectTextStyle(): Uses the given source TextStyle to modify the
  89.   given target TextStyle according to the given mode, in a manner
  90.   similar to that used in TTEView.SetOneStyle().  Note that
  91.   "mode" may include flags for setting the alignment, as defined
  92.   above; if present, they are ignored. }
  93. PROCEDURE AffectTextStyle(
  94.                         theMode:        INTEGER;
  95.                     VAR    source:            TextStyle;    { not changed }
  96.                     VAR    target:            TextStyle);
  97.     BEGIN
  98.     IF (theMode IN [doAll, doAllAndAlign])
  99.     THEN
  100.         target := source    { ignore alignment }
  101.     ELSE
  102.         BEGIN
  103.         IF BAND(theMode, doFont) <> 0
  104.         THEN
  105.             target.tsFont := source.tsFont;
  106.         
  107.         IF BAND(theMode, doPlusFace) <> 0
  108.         THEN
  109.             target.tsFace := target.tsFace + source.tsFace
  110.         ELSE IF BAND(theMode, doMinusFace) <> 0
  111.         THEN
  112.             target.tsFace := target.tsFace - source.tsFace
  113.         ELSE IF BAND(theMode, doFace) <> 0
  114.         THEN
  115.             target.tsFace := source.tsFace;
  116.         
  117.         IF BAND(theMode, doColor) <> 0
  118.         THEN
  119.             target.tsColor := source.tsColor;
  120.         
  121.         IF BAND(theMode, addSize) <> 0
  122.         THEN
  123.             target.tsSize := target.tsSize + source.tsSize
  124.         ELSE IF BAND(theMode, doSize) <> 0
  125.         THEN
  126.             target.tsSize := source.tsSize;
  127.         
  128.         { make sure that condense and extend are never turned on together }
  129.         IF (theMode IN [doAll, doAllAndAlign, doPlusFace, doFace]) &
  130.            (target.tsFace * [condense, extend] = [condense, extend])
  131.         THEN
  132.             target.tsFace := target.tsFace - [condense, extend];
  133.         END;
  134.     END;  { AffectTextStyle }
  135.     
  136. {——————————————————————————————————————————————————————————————————————————————}
  137. {$ AUtil}
  138.  
  139. { AffectTextAlignment(): Uses the given source  alignment to modify
  140.   the given target alignment according to the given mode, in a
  141.   manner similar to that used in TTEView.SetOneStyle().  Note that
  142.   "mode" may include flags for setting the alignment, as defined
  143.   above. }
  144. PROCEDURE AffectTextAlignment(
  145.                         theMode:        INTEGER;
  146.                         source:            INTEGER;
  147.                     VAR    target:            INTEGER);
  148.     BEGIN
  149.     IF (theMode = doAllAndAlign) |
  150.        (BAND(theMode, doAlign) <> 0)
  151.     THEN
  152.         target := source;    { !!! GetActualJustification(source) ??? }
  153.     END;  { AffectTextAlignment }
  154.     
  155. {——————————————————————————————————————————————————————————————————————————————}
  156. {$ AUtil}
  157.  
  158. { AffectTextStyleAndAlign(): Uses the given source TextStyle and
  159.   alignment to modify the given target TextStyle and alignment
  160.   according to the given mode, in a manner similar to that used in
  161.   TTEView.SetOneStyle().  Note that "mode" may include flags for
  162.   setting the alignment, as defined above. }
  163. PROCEDURE AffectTextStyleAndAlign(
  164.                         theMode:        INTEGER;
  165.                     VAR    sourceTS:        TextStyle;    { not changed }
  166.                         sourceAlign:    INTEGER;
  167.                     VAR    targetTS:        TextStyle;
  168.                     VAR    targetAlign:    INTEGER);
  169.     BEGIN
  170.     AffectTextStyle(theMode, sourceTS, targetTS);
  171.     AffectTextAlignment(theMode, sourceAlign, targetAlign);
  172.     END;  { AffectTextStyleAndAlign }
  173.  
  174.  
  175. {###############################################################################
  176. TCharDialogView
  177. ###############################################################################}
  178.  
  179. {------------------------------------------------------------------------------}
  180. {$S AOpen}
  181.  
  182. { PostRes(): Initialize the dialog's subview references. }
  183. PROCEDURE TCharDialogView.PostRes;
  184.                         OVERRIDE;
  185.     VAR
  186.         aView:             TView;
  187.  
  188.     BEGIN
  189.     INHERITED PostRes;
  190.     
  191.     aView := FindSubView('sclu');
  192.     FailNil(aView);
  193.     fSizeCluster := TSizeCluster(aView); 
  194.  
  195.     aView := FindSubView('just');
  196.     FailNil(aView);
  197.     fJustCluster := TJustifyCluster(aView); 
  198.     
  199.     aView := FindSubView('flst');
  200.     FailNil(aView);
  201.     fFontListView := TFontListView(aView);
  202.     
  203.     aView := FindSubView('samp');
  204.     FailNil(aView);
  205.     fSampleText := TSampleText(aView);
  206.     
  207.     aView := FindSubView('face');
  208.     FailNil(aView);
  209.     fFaceCluster := TFaceCluster(aView);
  210.     END;  { PostRes }
  211.  
  212. {------------------------------------------------------------------------------}
  213. {$S ACharDlg}
  214.         
  215. { SetDialogInfo(): Initializes the dialog to reflect the given TextStyle
  216.   record and alignment value. }
  217. PROCEDURE TCharDialogView.SetDialogInfo(
  218.                         theStyle:            TextStyle;
  219.                         alignment:            INTEGER;
  220.                         redraw:                BOOLEAN);
  221.     BEGIN
  222.     WITH theStyle DO
  223.         BEGIN
  224.         SetTextFont(tsFont, redraw);
  225.         SetTextSize(tsSize, redraw);
  226.         SetTextFace(tsFace, redraw);
  227.         SetTextColor(tsColor, redraw);
  228.         END;
  229.     
  230.     SetTextJust(alignment, redraw);
  231.     END;  { SetDialogInfo }
  232.  
  233. {------------------------------------------------------------------------------}
  234. {$S ACharDlg}
  235.  
  236. { GetDialogInfo(): Returns the dialog's current TextStyle record and
  237.   alignment value. }
  238. PROCEDURE TCharDialogView.GetDialogInfo(
  239.                     VAR    theStyle:            TextStyle;
  240.                     VAR    alignment:            INTEGER);
  241.     BEGIN
  242.     fSampleText.GetTextInfo(theStyle, alignment);
  243.     END;  { GetDialogInfo }
  244.  
  245. {------------------------------------------------------------------------------}
  246. {$S ACharDlg}
  247.  
  248. PROCEDURE TCharDialogView.SetTextFont(
  249.                         theFont:            INTEGER;
  250.                         redraw:                BOOLEAN);
  251.     BEGIN
  252.     { the call below is redundant, if in response to DoChoice(mFontChanged) }
  253.     fFontListView.SetTextFont(theFont,redraw);
  254.     
  255.     { always necessary }
  256.     fSizeCluster.SetTextFont(theFont, redraw);
  257.     fSampleText.SetTextFont(theFont, redraw);
  258.     END; {SetTextFont}
  259.  
  260. {------------------------------------------------------------------------------}
  261. {$S ACharDlg}
  262. PROCEDURE TCharDialogView.SetTextSize(
  263.                         theSize:            INTEGER;
  264.                         redraw:                BOOLEAN);
  265.     BEGIN
  266.     fSizeCluster.SetTextSize(theSize,redraw);
  267.     fSampleText.SetTextSize(theSize,redraw);
  268.     END; {SetTextSize}
  269.  
  270. {------------------------------------------------------------------------------}
  271. {$S ACharDlg}
  272. PROCEDURE TCharDialogView.SetTextFace(
  273.                         theFace:            Style;
  274.                         redraw:                BOOLEAN);
  275.     BEGIN
  276.     fSampleText.SetTextFace(theFace,redraw);
  277.     fFaceCluster.SetTextFace(theFace,redraw);
  278.     END; {SetTextFace}
  279.  
  280. {------------------------------------------------------------------------------}
  281. {$S ACharDlg}
  282.         
  283. PROCEDURE TCharDialogView.SetTextColor(
  284.                         theColor:            RGBColor;
  285.                         redraw:                BOOLEAN);
  286.     BEGIN
  287.     fSampleText.SetTextColor(theColor, redraw);
  288.     END; {SetTextColor}
  289.  
  290. {------------------------------------------------------------------------------}
  291. {$S ACharDlg}
  292.  
  293. PROCEDURE TCharDialogView.SetTextJust(
  294.                         alignment:            INTEGER;
  295.                         redraw:                BOOLEAN);
  296.     BEGIN
  297.     fSampleText.SetTextJust(alignment, redraw);
  298.     fJustCluster.SetTextJust(alignment, redraw);
  299.     END;  { SetTextJust }
  300.  
  301.  
  302. {------------------------------------------------------------------------------}
  303. {$S ACharDlg}
  304. PROCEDURE TCharDialogView.DoChoice(
  305.                         origView:             TView;
  306.                         itsChoice:             INTEGER);
  307.                         OVERRIDE;
  308.     BEGIN
  309.     CASE itsChoice OF
  310.         mFontChanged:
  311.             BEGIN
  312.             SetTextFont(fFontListView.GetTextFont,kRedraw);
  313.             END;
  314.             
  315.         mFontSizeChanged:
  316.             BEGIN
  317.             SetTextSize(fSizeCluster.GetTextSize,kRedraw);
  318.             END;
  319.             
  320.         OTHERWISE
  321.             INHERITED DoChoice(origView, itsChoice);
  322.         END;  { case }
  323.     END; { DoChoice }
  324.     
  325.     
  326. {###############################################################################
  327. TValueCheckBox
  328. ###############################################################################}
  329.  
  330. {------------------------------------------------------------------------------}
  331. {$S AUtilities}
  332.  
  333. PROCEDURE TValueCheckBox.IRes(
  334.                         itsDocument:    TDocument;
  335.                         itsSuperView:    TView;
  336.                     VAR itsParams:        Ptr);
  337.                         OVERRIDE;
  338.     BEGIN
  339.     INHERITED IRes(itsDocument, itsSuperView, itsParams);
  340.     
  341.     WITH ValueCheckBoxTemplatePtr(itsParams)^ DO
  342.         BEGIN
  343.         fNumber := number;
  344.         END;
  345.  
  346.     OffsetPtr(itsParams, SIZEOF(ValueCheckBoxTemplate));
  347.     END;  { IRes }
  348.  
  349. {------------------------------------------------------------------------------}
  350. {$S AUtilities}
  351.  
  352. PROCEDURE TValueCheckBox.SetNumber(
  353.                         number:            INTEGER);
  354.     BEGIN
  355.     fNumber := number;
  356.     END;  { SetNumber }
  357.  
  358. {------------------------------------------------------------------------------}
  359. {$S AUtilities}
  360.  
  361. FUNCTION  TValueCheckBox.GetNumber
  362.                         :INTEGER;
  363.     BEGIN
  364.     GetNumber := fNumber;
  365.     END;  { GetNumber }
  366.  
  367. {------------------------------------------------------------------------------}
  368. {$S AFields}
  369.                         
  370. {$IFC qInspector}
  371. PROCEDURE TValueCheckBox.Fields(
  372.                         PROCEDURE DoToField(
  373.                             fieldName:        Str255;
  374.                             fieldAddr:        Ptr;
  375.                             fieldType:        INTEGER));
  376.                         OVERRIDE;
  377.     BEGIN
  378.     DoToField('TValueCheckBox', NIL, bClass);
  379.     DoToField('fNumber', @fNumber, bInteger);
  380.  
  381.     INHERITED Fields(DoToField);
  382.     END;  { Fields }
  383. {$ENDC qDebug}
  384.     
  385.     
  386. {###############################################################################
  387. TValueRadio
  388. ###############################################################################}
  389.  
  390. {------------------------------------------------------------------------------}
  391. {$S AUtilities}
  392.  
  393. PROCEDURE TValueRadio.IRes(
  394.                         itsDocument:    TDocument;
  395.                         itsSuperView:    TView;
  396.                     VAR itsParams:        Ptr);
  397.                         OVERRIDE;
  398.     BEGIN
  399.     INHERITED IRes(itsDocument, itsSuperView, itsParams);
  400.     
  401.     WITH ValueRadioTemplatePtr(itsParams)^ DO
  402.         BEGIN
  403.         fNumber := number;
  404.         END;
  405.  
  406.     OffsetPtr(itsParams, SIZEOF(ValueRadioTemplate));
  407.     END;  { IRes }
  408.  
  409. {------------------------------------------------------------------------------}
  410. {$S AUtilities}
  411.  
  412. PROCEDURE TValueRadio.SetNumber(
  413.                         number:            INTEGER);
  414.     BEGIN
  415.     fNumber := number;
  416.     END;  { SetNumber }
  417.  
  418. {------------------------------------------------------------------------------}
  419. {$S AUtilities}
  420.  
  421. FUNCTION  TValueRadio.GetNumber
  422.                         :INTEGER;
  423.     BEGIN
  424.     GetNumber := fNumber;
  425.     END;  { GetNumber }
  426.  
  427. {------------------------------------------------------------------------------}
  428. {$S AFields}
  429.                         
  430. {$IFC qInspector}
  431. PROCEDURE TValueRadio.Fields(
  432.                         PROCEDURE DoToField(
  433.                             fieldName:        Str255;
  434.                             fieldAddr:        Ptr;
  435.                             fieldType:        INTEGER));
  436.                         OVERRIDE;
  437.     BEGIN
  438.     DoToField('TValueRadio', NIL, bClass);
  439.     DoToField('fNumber', @fNumber, bInteger);
  440.  
  441.     INHERITED Fields(DoToField);
  442.     END;  { Fields }
  443. {$ENDC qDebug}
  444.  
  445.  
  446.  
  447. {###############################################################################
  448. TSetCluster
  449. ###############################################################################}
  450.  
  451. {------------------------------------------------------------------------------}
  452. {$S AUtilities}
  453.         
  454. { IRes(): Sets fSet to []. }
  455. PROCEDURE TSetCluster.IRes(
  456.                         itsDocument:    TDocument;
  457.                         itsSuperView:    TView;
  458.                     VAR itsParams:        Ptr);
  459.                         OVERRIDE;
  460.     BEGIN
  461.     INHERITED IRes(itsDocument, itsSuperView, itsParams);
  462.     
  463.     fSet := [];
  464.     END;  { IRes }
  465.  
  466. {------------------------------------------------------------------------------}
  467. {$S AUtilities}
  468.         
  469. PROCEDURE TSetCluster.SetTheSet(
  470.                         theSet:            ValueSet;
  471.                         redraw:            BOOLEAN);
  472.     
  473.     {--------------------------------------------------------------------------}
  474.     
  475.     PROCEDURE SetOrClearSubview(aView: TView);
  476.         VAR
  477.             number:            INTEGER;
  478.             inNewState:        BOOLEAN;
  479.         
  480.         BEGIN
  481.         IF Member(aView, TValueCheckbox)
  482.         THEN
  483.             BEGIN
  484.             number := TValueCheckbox(aView).GetNumber;
  485.             
  486.             IF (theSet = []) & (number = kEmptySet)
  487.             THEN
  488.                 TValueCheckbox(aView).SetState(TRUE, redraw)
  489.             ELSE
  490.                 BEGIN
  491.                 inNewState := (number IN theSet);
  492.                 
  493.                 IF (TValueCheckbox(aView).IsOn <> inNewState)
  494.                 THEN
  495.                     TValueCheckbox(aView).SetState(inNewState, redraw);
  496.                 END;  { else }
  497.             END;  { if is TValueCheckbox }
  498.         END;  { SetOrClearSubview }
  499.     
  500.     {--------------------------------------------------------------------------}
  501.     
  502.     BEGIN  { SetTheSet }
  503.     IF (theSet <> fSet)
  504.     THEN
  505.         BEGIN
  506.         fSet := theSet;
  507.         
  508.         EachSubview(SetOrClearSubview);
  509.         END;
  510.     END;  { SetTheSet }
  511.  
  512. {------------------------------------------------------------------------------}
  513. {$S AUtilities}
  514.  
  515. FUNCTION TSetCluster.GetTheSet
  516.                         : ValueSet;
  517.     BEGIN
  518.     GetTheSet := fSet;
  519.     END;  { GetTheSet }
  520.  
  521. {------------------------------------------------------------------------------}
  522. {$S AUtilities}
  523.         
  524. PROCEDURE TSetCluster.DoCheckBoxHit(
  525.                     VAR    origView:        TView;
  526.                     VAR    itsChoice:        INTEGER);
  527.     VAR
  528.         number:            INTEGER;
  529.     
  530.     BEGIN
  531.     { modify the set value as necessary }
  532.     IF Member(origView, TValueCheckBox)
  533.     THEN
  534.         BEGIN
  535.         number := TValueCheckBox(origView).GetNumber;
  536.         
  537.         IF (kMinValue <= number) & (number <= kMaxValue)
  538.         THEN
  539.             BEGIN
  540.             IF (TValueCheckBox(origView).IsOn)
  541.             THEN
  542.                 SetTheSet(fSet + [number], kRedraw)
  543.             ELSE
  544.                 SetTheSet(fSet - [number], kRedraw);
  545.             END  { if in range }
  546.         ELSE IF (number = kEmptySet)
  547.         THEN
  548.             SetTheSet([], kRedraw)
  549.         ELSE
  550.             BEGIN
  551.             {$IFC qDebug}
  552.             (*
  553.             write(  'In TSetCluster.DoChoice(), number is out of range: ');
  554.             writeln('(', kMinValue:1, ' <= ', number:1, ') & (', number:1, ' <= ', kMaxValue:1, ')');
  555.             *)
  556.             {$ENDC qDebug}
  557.             END;  { out of range }
  558.         END;  { if is member }
  559.     END;  { DoCheckBoxHit }
  560.  
  561. {------------------------------------------------------------------------------}
  562. {$S AUtilities}
  563.         
  564. PROCEDURE TSetCluster.DoRadioHit(
  565.                     VAR    origView:        TView;
  566.                     VAR    itsChoice:        INTEGER);
  567.     VAR
  568.         number:            INTEGER;
  569.     
  570.     BEGIN
  571.     IF (Member(origView, TValueRadio))
  572.     THEN
  573.         BEGIN
  574.         number := TValueRadio(origView).GetNumber;
  575.         
  576.         IF (kMinValue <= number) & (number <= kMaxValue)
  577.         THEN
  578.             SetTheSet([number], kRedraw)
  579.         ELSE IF (number = kEmptySet)
  580.         THEN
  581.             SetTheSet([], kRedraw)
  582.         ELSE
  583.             BEGIN
  584.             {$IFC qDebug}
  585.             write(  'In TSetCluster.DoChoice(), number is out of range: ');
  586.             writeln('(', kMinValue:1, ' <= ', number:1, ') & (', number:1, ' <= ', kMaxValue:1, ')');
  587.             {$ENDC qDebug}
  588.             END;  { out of range }
  589.         END;  { if is member }
  590.     END;  { DoRadioHit }
  591.  
  592. {------------------------------------------------------------------------------}
  593. {$S AUtilities}
  594.  
  595. PROCEDURE TSetCluster.DoChoice(
  596.                         origView:        TView;
  597.                         itsChoice:        INTEGER);
  598.                         OVERRIDE;
  599.     VAR
  600.         callDoChoice:    BOOLEAN;
  601.  
  602.     BEGIN
  603.     IF (origView.fSuperView = SELF)    { Only worry about it if it's our subview! }
  604.     THEN
  605.         BEGIN
  606.         CASE itsChoice OF
  607.             mCheckBoxHit:    DoCheckBoxHit(origView, itsChoice);
  608.             mRadioHit:        DoRadioHit(origView, itsChoice);
  609.             
  610.             OTHERWISE        ;{ nothing special }
  611.             END;  { case }
  612.         END;  { our subView }
  613.     
  614.     INHERITED DoChoice(origView, itsChoice);
  615.     END;  { DoChoice }
  616.  
  617. {------------------------------------------------------------------------------}
  618. {$S AFields}
  619.  
  620. {$IFC qInspector}
  621. PROCEDURE TSetCluster.Fields(
  622.                         PROCEDURE DoToField(
  623.                             fieldName:        Str255;
  624.                             fieldAddr:        Ptr;
  625.                             fieldType:        INTEGER));
  626.                         OVERRIDE;
  627.     VAR
  628.         i:                ValueRange;
  629.         iStr:            Str255;
  630.         isInSet:        BOOLEAN;
  631.  
  632.     BEGIN
  633.     DoToField('TSetCluster', NIL, bClass);
  634.     DoToField('fSet', @fSet, bHexLongint);    { because it contains only 31 members }
  635.     
  636.     FOR i := kMinValue to kMaxValue DO
  637.         BEGIN
  638.         isInSet := i IN fSet;
  639.         
  640.         NumToString(LONGINT(i), iStr);
  641.         DoToField(Concat('    ', iStr), @isInSet, bBoolean);
  642.         END;
  643.  
  644.     INHERITED Fields(DoToField);
  645.     END;  { Fields }
  646. {$ENDC qDebug}
  647.     
  648.     
  649. {###############################################################################
  650. TValueRadioCluster
  651. ###############################################################################}
  652.  
  653. {------------------------------------------------------------------------------}
  654. {$S AUtilities}
  655.  
  656. FUNCTION  TValueRadioCluster.GetNumber
  657.                         :INTEGER;
  658.     VAR
  659.         Valueradio:        TValueRadio;
  660.     
  661.     {--------------------------------------------------------------------------}
  662.     
  663.     FUNCTION  IsSelectedValueRadio(aView: TView): BOOLEAN;
  664.         BEGIN
  665.         IsSelectedValueRadio := Member(aView, TValueRadio) & TValueRadio(aView).IsOn;
  666.         END;  { IsSelectedValueRadio }
  667.         
  668.     
  669.     {--------------------------------------------------------------------------}
  670.     
  671.     BEGIN  { GetNumber }
  672.     Valueradio := TValueRadio(FirstSubViewThat(IsSelectedValueRadio));
  673.     
  674.     IF (Valueradio = NIL)
  675.     THEN
  676.         GetNumber := kBadValue
  677.     ELSE
  678.         GetNumber := Valueradio.GetNumber;
  679.     END;   { GetNumber }
  680.     
  681.  
  682. {------------------------------------------------------------------------------}
  683. {$S AUtilities}
  684.  
  685. PROCEDURE TValueRadioCluster.SetNumber(
  686.                         number            :INTEGER;
  687.                         redraw:            BOOLEAN);
  688.     
  689.     {--------------------------------------------------------------------------}
  690.     
  691.     PROCEDURE SetOrClearSubview(aView: TView);
  692.         BEGIN
  693.         IF Member(aView, TValueRadio)
  694.         THEN
  695.             TValueRadio(aView).SetState((TValueRadio(aView).GetNumber = number),
  696.                                        redraw);
  697.         END;  { SetOrClearSubview }
  698.         
  699.     
  700.     {--------------------------------------------------------------------------}
  701.     
  702.     BEGIN  { SetNumber }
  703.     EachSubview(SetOrClearSubview);
  704.     END;   { SetNumber }
  705.     
  706.  
  707. {------------------------------------------------------------------------------}
  708. {$S AFields}
  709.                         
  710. {$IFC qInspector}
  711. PROCEDURE TValueRadioCluster.Fields(
  712.                         PROCEDURE DoToField(
  713.                             fieldName:        Str255;
  714.                             fieldAddr:        Ptr;
  715.                             fieldType:        INTEGER));
  716.                         OVERRIDE;
  717.     VAR
  718.         number:            INTEGER;
  719.     
  720.     BEGIN
  721.     DoToField('TValueRadioCluster', NIL, bClass);
  722.     
  723.     number := GetNumber;
  724.     DoToField('current number', @number, bInteger);
  725.  
  726.     INHERITED Fields(DoToField);
  727.     END;  { Fields }
  728. {$ENDC qDebug}
  729.  
  730.  
  731. {###############################################################################
  732. TSampleText
  733. ###############################################################################}
  734.  
  735. {------------------------------------------------------------------------------}
  736. {$S AOpen}
  737.  
  738. { PostRes(): Initialize the dialog's subview references. }
  739. PROCEDURE TSampleText.PostRes;
  740.                         OVERRIDE;
  741.     BEGIN
  742.     ChangeWrap(TRUE,            { DO wrap text }
  743.                kDontRedraw);    { DON'T redraw }
  744.     END;  { PostRes }
  745.  
  746. {------------------------------------------------------------------------------}
  747. {$S ACharDlg}
  748. PROCEDURE TSampleText.GetTextInfo(
  749.                     VAR    theStyle:            TextStyle;
  750.                     VAR    alignment:            INTEGER);
  751.     BEGIN
  752.     theStyle  := fTextStyle;
  753.     alignment := fJust;
  754.     END;  { GetTextInfo }
  755.  
  756. {------------------------------------------------------------------------------}
  757. {$S ACharDlg}
  758. PROCEDURE TSampleText.GetTextStyle(
  759.                     VAR    theStyle:            TextStyle);
  760.     BEGIN
  761.     theStyle  := fTextStyle;
  762.     END;  { GetTextStyle }
  763.                                 
  764. {------------------------------------------------------------------------------}
  765. {$S ACharDlg}
  766. PROCEDURE TSampleText.SetTextStyle(
  767.                         mode:                INTEGER;
  768.                         theTextStyle:         TextStyle;
  769.                         redraw:             BOOLEAN);
  770.     VAR
  771.         localTextStyle:    TextStyle;
  772.         ctlRect:        Rect;
  773.     
  774.     BEGIN
  775.     localTextStyle := fTextStyle;                { a TStaticText field }
  776.     AffectTextStyle(mode, theTextStyle, localTextStyle);
  777.     InstallTextStyle(localTextStyle, kDontRedraw);    { a TControl method }
  778.  
  779.     IF redraw
  780.     THEN
  781.         BEGIN
  782.         ControlArea(ctlRect);
  783.         InvalidRect(ctlRect);
  784.         END;
  785.     END; { SetTextStyle }
  786.     
  787. {------------------------------------------------------------------------------}
  788. {$S ACharDlg}
  789. PROCEDURE TSampleText.SetTextFont(
  790.                         theFont:            INTEGER;
  791.                         redraw:                BOOLEAN);
  792.     VAR
  793.         aTextStyle:        TextStyle;
  794.     
  795.     BEGIN
  796.     GetTextStyle(aTextStyle);
  797.     
  798.     IF (theFont <> aTextStyle.tsFont)
  799.     THEN
  800.         BEGIN
  801.         aTextStyle.tsFont := theFont;
  802.         SetTextStyle(doFont,aTextStyle,redraw);
  803.         END;
  804.     END; {SetTextFont}
  805.  
  806. {------------------------------------------------------------------------------}
  807. {$S ACharDlg}
  808. PROCEDURE TSampleText.SetTextSize(
  809.                         theSize:            INTEGER;
  810.                         redraw:                BOOLEAN);
  811.     VAR
  812.         aTextStyle:        TextStyle;
  813.     
  814.     BEGIN
  815.     GetTextStyle(aTextStyle);
  816.     
  817.     IF (aTextStyle.tsSize <> theSize)
  818.     THEN
  819.         BEGIN
  820.         aTextStyle.tsSize := theSize;
  821.         SetTextStyle(doSize,aTextStyle,redraw)
  822.         END;
  823.     END; {SetTextSize}
  824.  
  825. {------------------------------------------------------------------------------}
  826. {$S ACharDlg}
  827. PROCEDURE TSampleText.SetTextFace(
  828.                         theFace:            Style;
  829.                         redraw:                BOOLEAN);
  830.     VAR
  831.         aTextStyle:        TextStyle;
  832.     
  833.     BEGIN
  834.     GetTextStyle(aTextStyle);
  835.     
  836.     IF (aTextStyle.tsFace <> theFace)
  837.     THEN
  838.         BEGIN
  839.         aTextStyle.tsFace := theFace;
  840.         SetTextStyle(doFace,aTextStyle,redraw);
  841.         END;
  842.     END; {SetTextFace}
  843.  
  844. {------------------------------------------------------------------------------}
  845. {$S ACharDlg}
  846.         
  847. PROCEDURE TSampleText.SetTextColor(
  848.                         theColor:            RGBColor;
  849.                         redraw:                BOOLEAN);
  850.     VAR
  851.         aTextStyle:        TextStyle;
  852.     
  853.     BEGIN
  854.     GetTextStyle(aTextStyle);
  855.     
  856.     IF (NOT SameRGBColor(aTextStyle.tsColor, theColor))    { UProtoUtilities }
  857.     THEN
  858.         BEGIN
  859.         aTextStyle.tsColor := theColor;
  860.         SetTextStyle(doColor,aTextStyle,redraw);
  861.         END;
  862.     END;  { SetTextColor }
  863.  
  864. {------------------------------------------------------------------------------}
  865. {$S ACharDlg}
  866.  
  867. PROCEDURE TSampleText.SetTextJust(
  868.                         alignment:            INTEGER;
  869.                         redraw:                BOOLEAN);
  870.     BEGIN
  871.     IF (fJust <> alignment)
  872.     THEN
  873.         SetJustification(alignment, redraw);
  874.     END;  { SetTextJust }
  875.  
  876.  
  877. {###############################################################################
  878. TJustifyCluster
  879. ###############################################################################}
  880.  
  881. {------------------------------------------------------------------------------}
  882. {$S AOpen}
  883.  
  884. { PostRes(): Initialize the dialog's subview references. }
  885. PROCEDURE TJustifyCluster.PostRes;
  886.                         OVERRIDE;
  887.     VAR
  888.         aView:             TView;
  889.  
  890.     BEGIN
  891.     INHERITED PostRes;
  892.     
  893.     aView := GetDialogView.FindSubView('samp');
  894.     FailNil(aView);
  895.     fSampleText := TSampleText(aView); 
  896.     END;  { PostRes }
  897.  
  898. {------------------------------------------------------------------------------}
  899. {$S ACharDlg}
  900. PROCEDURE TJustifyCluster.DoChoice(
  901.                         origView:            TView;
  902.                         itsChoice:            INTEGER);
  903.     BEGIN
  904.     INHERITED DoChoice(origView,itsChoice);
  905.  
  906.     IF (itsChoice = mRadioHit) & (TRadio(origView).IsOn)
  907.     THEN
  908.         fSampleText.SetTextJust(GetNumber,kRedraw)
  909.     END;  { DoChoice }
  910.  
  911. {------------------------------------------------------------------------------}
  912. {$S ACharDlg}
  913.  
  914. PROCEDURE TJustifyCluster.SetTextJust(
  915.                         alignment:            INTEGER;
  916.                         redraw:                BOOLEAN);
  917.     BEGIN
  918.     IF (GetNumber <> alignment)
  919.     THEN
  920.         SetNumber(alignment, redraw);
  921.     END;  { SetTextJust }
  922.  
  923.  
  924. {###############################################################################
  925. TStyleCluster
  926. ###############################################################################}
  927.  
  928. {------------------------------------------------------------------------------}
  929. {$S ACharDlg}
  930.  
  931. PROCEDURE TStyleCluster.SetTextFace(
  932.                         theFace:            Style;
  933.                         redraw:                BOOLEAN);
  934.     VAR
  935.         theSet:            ValueSet;        { see UProtoControls.p }
  936.         aStyleItem:        StyleItem;        { see IM v1 p201 }
  937.     
  938.     BEGIN
  939.     IF (GetTextFace <> theFace)
  940.     THEN
  941.         BEGIN                            { convert Style to ValueSet }
  942.         theSet := [];
  943.     
  944.         IF (theFace <> [])
  945.         THEN
  946.             BEGIN
  947.             FOR aStyleItem := bold TO shadow DO        { ignore condense and extend }
  948.                 BEGIN
  949.                 IF (aStyleItem IN theFace)
  950.                 THEN
  951.                     theSet := theSet + [ord(aStyleItem)];
  952.                 END;  { for }
  953.             END;  { if }
  954.         
  955.         SetTheSet(theSet, redraw);
  956.         END;
  957.     END;  { SetTextFace }
  958.  
  959. {------------------------------------------------------------------------------}
  960. {$S ACharDlg}
  961.  
  962. FUNCTION  TStyleCluster.GetTextFace
  963.                         : Style;
  964.     VAR
  965.         aStyleItem:        StyleItem;
  966.         result:            Style;
  967.         
  968.     BEGIN
  969.     result := [];
  970.     
  971.     IF (fSet <> [])
  972.     THEN
  973.         BEGIN
  974.         FOR aStyleItem := bold TO shadow DO
  975.             BEGIN
  976.             IF (ord(aStyleItem) IN fSet)
  977.             THEN
  978.                 result := result + [aStyleItem];
  979.             END;  { for }
  980.         END;  { if }
  981.     
  982.     GetTextFace := result;
  983.     END;  { GetTextFace }
  984.  
  985.  
  986. {###############################################################################
  987. TSpaceCluster
  988. ###############################################################################}
  989.  
  990. {------------------------------------------------------------------------------}
  991. {$S ACharDlg}
  992.  
  993. PROCEDURE TSpaceCluster.SetTextFace(
  994.                         theFace:            Style;
  995.                         redraw:                BOOLEAN);
  996.     VAR
  997.         theNumber:        INTEGER;
  998.     
  999.     BEGIN
  1000.     IF (GetTextFace <> theFace)
  1001.     THEN
  1002.         BEGIN                            { convert Style to INTEGER }
  1003.         IF (condense IN theFace)
  1004.         THEN
  1005.             theNumber := ord(condense)
  1006.         ELSE IF (extend IN theFace)
  1007.         THEN
  1008.             theNumber := ord(extend)
  1009.         ELSE
  1010.             theNumber := kNormalSpacing;
  1011.         
  1012.         SetNumber(theNumber, redraw);
  1013.         END;
  1014.     END;  { SetTextFace }
  1015.  
  1016. {------------------------------------------------------------------------------}
  1017. {$S ACharDlg}
  1018.  
  1019. FUNCTION  TSpaceCluster.GetTextFace
  1020.                         : Style;
  1021.     VAR
  1022.         theNumber:        INTEGER;
  1023.     
  1024.     BEGIN
  1025.     theNumber := GetNumber;
  1026.     
  1027.     IF (theNumber = ord(condense))
  1028.     THEN
  1029.         GetTextFace := [condense]
  1030.     ELSE IF (theNumber = ord(extend))
  1031.     THEN
  1032.         GetTextFace := [extend]
  1033.     ELSE
  1034.         GetTextFace := [];
  1035.     END;  { GetTextFace }
  1036.  
  1037.  
  1038. {###############################################################################
  1039. TFaceCluster
  1040. ###############################################################################}
  1041.  
  1042. {------------------------------------------------------------------------------}
  1043. {$S AOpen}
  1044.  
  1045. { PostRes(): Initialize the dialog's subview references. }
  1046. PROCEDURE TFaceCluster.PostRes;
  1047.                         OVERRIDE;
  1048.     VAR
  1049.         aView:             TView;
  1050.  
  1051.     BEGIN
  1052.     INHERITED PostRes;
  1053.     
  1054.     aView := FindSubView('styl');
  1055.     FailNil(aView);
  1056.     fStyleCluster := TStyleCluster(aView); 
  1057.  
  1058.     aView := FindSubView('spac');
  1059.     FailNil(aView);
  1060.     fSpaceCluster := TSpaceCluster(aView); 
  1061.     
  1062.     aView := GetDialogView.FindSubView('samp');
  1063.     FailNil(aView);
  1064.     fSampleText := TSampleText(aView); 
  1065.     END;  { PostRes }
  1066.  
  1067. {------------------------------------------------------------------------------}
  1068. {$S ACharDlg}
  1069. PROCEDURE TFaceCluster.DoChoice(
  1070.                         origView:            TView;
  1071.                         itsChoice:            INTEGER);
  1072.     BEGIN
  1073.     IF (itsChoice IN [mCheckBoxHit, mRadioHit])
  1074.     THEN
  1075.         fSampleText.SetTextFace(GetTextFace, kRedraw);
  1076.     
  1077.     INHERITED DoChoice(origView, itsChoice);
  1078.     END;  { DoChoice }
  1079.  
  1080. {------------------------------------------------------------------------------}
  1081. {$S ACharDlg}
  1082.  
  1083. PROCEDURE TFaceCluster.SetTextFace(
  1084.                         theFace:            Style;
  1085.                         redraw:                BOOLEAN);
  1086.     BEGIN
  1087.     IF (GetTextFace <> theFace)
  1088.     THEN
  1089.         BEGIN
  1090.         fStyleCluster.SetTextFace(theFace, redraw);
  1091.         fSpaceCluster.SetTextFace(theFace, redraw);
  1092.         END;
  1093.     END;  { SetTextFace }
  1094.  
  1095. {------------------------------------------------------------------------------}
  1096. {$S ACharDlg}
  1097.  
  1098. FUNCTION  TFaceCluster.GetTextFace
  1099.                         : Style;
  1100.     BEGIN
  1101.     GetTextFace := fStyleCluster.GetTextFace + fSpaceCluster.GetTextFace;
  1102.     END;  { GetTextFace }
  1103.  
  1104.  
  1105. {###############################################################################
  1106. TFontListView
  1107. ###############################################################################}
  1108.  
  1109. {------------------------------------------------------------------------------}
  1110. {$S AOpen}
  1111.         
  1112. { PostRes(): Calls InitFontList(). }
  1113. PROCEDURE TFontListView.PostRes;
  1114.                         OVERRIDE;
  1115.     BEGIN
  1116.     INHERITED PostRes;
  1117.     
  1118.     { build the font list }
  1119.     InitFontList;
  1120.     
  1121.     {$IFC qDebug}
  1122.     Assertion((fNumOfRows >= 1), AtStr('(fNumOfRows >= 1)'));
  1123.     {$ENDC qDebug}
  1124.     
  1125.     { select the first item }
  1126.     SetSelectionRect(1, 1, 1, 1, kDontExtend, kHighlight, kSelect);
  1127.     END;  { PostRes }
  1128.  
  1129. {------------------------------------------------------------------------------}
  1130. {$S AOpen}
  1131. PROCEDURE TFontListView.InitFontList;
  1132.  
  1133.     VAR
  1134.         pFondIDs:            FontListPtr;
  1135.         i:                    INTEGER;
  1136.         noOfFonds:            INTEGER;
  1137.         aString:            Str255;
  1138.         
  1139.     {--------------------------------------------------------------------------}
  1140.  
  1141.     FUNCTION FondAfter(VAR fontName: Str255): INTEGER;
  1142.     { Find the FOND whose name follows fontName alphabetically, and return its id and name }
  1143.  
  1144.         VAR
  1145.             theFondResource:    Handle;
  1146.             lastID:                INTEGER;
  1147.             thisID:                INTEGER;
  1148.             itsType:            ResType;
  1149.             index:                INTEGER;
  1150.             foundFOND:            BOOLEAN;
  1151.             lastName:            Str255;
  1152.             thisName:            Str255;
  1153.  
  1154.         BEGIN
  1155.         lastID := 0;
  1156.         foundFOND := FALSE;
  1157.         lastName := '~~~~~~~~';
  1158.         
  1159.         FOR index := 1 to noOfFonds DO
  1160.             BEGIN
  1161.             theFondResource := GetIndResource('FOND', index);
  1162.             GetResInfo(theFondResource, thisID, itsType, thisName);
  1163.             
  1164.             IF (thisName > fontName) & (thisName < lastName) THEN
  1165.                 BEGIN
  1166.                 lastID := thisID;
  1167.                 CopyStr255(thisName, @lastName);
  1168.                 foundFOND := TRUE;
  1169.                 END;
  1170.             END;
  1171.             
  1172.         IF foundFOND THEN
  1173.             CopyStr255(lastName, @fontName)
  1174.         ELSE                                            { Skip duplicate FOND names }
  1175.             fontName := '';
  1176.         
  1177.         FondAfter := lastID;
  1178.         END;  { FondAfter }
  1179.         
  1180.     {--------------------------------------------------------------------------}
  1181.  
  1182.     BEGIN { InitFontList }
  1183.     fFontList := NIL;
  1184.     noOfFonds := CountResources('FOND');
  1185.     IF noOfFonds > kMaxFonds THEN
  1186.         noOfFonds := kMaxFonds;
  1187.     pFondIDs := FontListPtr(NewPermPtr(noOfFonds * sizeof(INTEGER)));
  1188.     FailNIL(pFondIDs);
  1189.  
  1190.     aString := ' ';
  1191.     FOR i := 1 TO noOfFonds DO
  1192.         BEGIN                                            { put each FOND's id in the list… }
  1193.         pFondIDs^[i] := FondAfter(aString);                { …in alphabetical order }
  1194.         IF length(aString) = 0 THEN                        { we finished early }
  1195.             BEGIN
  1196.             noOfFonds := i-1;
  1197.             LEAVE;
  1198.             END;
  1199.         END;
  1200.  
  1201.     fFontList := pFondIDs;
  1202.     InsItemLast(noOfFonds)
  1203.     END;  { InitFontList }
  1204.  
  1205. {------------------------------------------------------------------------------}
  1206. {$S AClose}
  1207. PROCEDURE TFontListView.Free;
  1208.                         OVERRIDE;
  1209.  
  1210.     BEGIN
  1211.     Ptr(fFontList) := DisposeIfPtr(fFontList);
  1212.  
  1213.     INHERITED Free;
  1214.     END;
  1215.  
  1216. {------------------------------------------------------------------------------}
  1217. {$S ACharDlg}
  1218. PROCEDURE TFontListView.GetItemText(
  1219.                         anItem:             INTEGER;
  1220.                     VAR aString:             Str255);
  1221.                         OVERRIDE;
  1222.  
  1223.     VAR
  1224.         theFondResource:    Handle;
  1225.         itsID:                INTEGER;
  1226.         itsType:            ResType;
  1227.  
  1228.     BEGIN
  1229.     theFondResource := GetResource('FOND', fFontList^[anItem]);
  1230.     GetResInfo(theFondResource, itsID, itsType, aString);
  1231.     END;
  1232.  
  1233. {------------------------------------------------------------------------------}
  1234. {$S ACharDlg}
  1235. PROCEDURE TFontListView.SetTextFont(
  1236.                         theFont:            INTEGER;
  1237.                         redraw:                BOOLEAN);
  1238.     VAR
  1239.         item:            INTEGER;
  1240.     
  1241.     BEGIN
  1242.     IF (GetTextFont <> theFont)
  1243.     THEN
  1244.         BEGIN
  1245.         item := fNumOfRows;        { find the list item that is displaying theFont }
  1246.         WHILE (item >= 1) & (fFontList^[item] <> theFont) DO
  1247.             BEGIN
  1248.             item := item - 1;
  1249.             END;
  1250.         
  1251.         IF (fFontList^[item] = theFont)    { found it }
  1252.         THEN
  1253.             BEGIN
  1254.             SelectItem(item,
  1255.                        kDontExtend,
  1256.                        kHighlight,
  1257.                        kSelect);
  1258.             END
  1259.         ELSE
  1260.             BEGIN
  1261.             SetEmptySelection(kHighlight);
  1262.             
  1263.             {$IFC qDebug}
  1264.             ProgramBreak('In TFontListView.SetTextFont(), a missing font was set (bad!).');
  1265.             {$ENDC qDebug}
  1266.             END;
  1267.         END;
  1268.     END;  { SetTextFont }
  1269.  
  1270. {------------------------------------------------------------------------------}
  1271. {$S ACharDlg}
  1272. FUNCTION TFontListView.GetTextFont
  1273.                         :INTEGER;
  1274.  
  1275.     VAR
  1276.         aString:        Str255;
  1277.         aFontNumber:    INTEGER;
  1278.  
  1279.     BEGIN
  1280.     GetItemText(LastSelectedItem,aString);
  1281.     GetFNum(aString,aFontNumber);
  1282.     GetTextFont := aFontNumber;
  1283.     END;
  1284.         
  1285. {------------------------------------------------------------------------------}
  1286. {$S ACharDlg}
  1287. PROCEDURE TFontListView.SelectItem(
  1288.                             anItem:         INTEGER;
  1289.                             extendSelection,
  1290.                             highlight,
  1291.                             select:         BOOLEAN);
  1292.                             OVERRIDE;
  1293.     BEGIN
  1294.     INHERITED SelectItem(anItem, extendSelection, highlight, select);
  1295.  
  1296.     IF select
  1297.     THEN
  1298.         DoChoice(SELF,mFontChanged)
  1299.     END;
  1300.  
  1301. {------------------------------------------------------------------------------}
  1302. {$S AFields}
  1303.  
  1304. {$IFC qInspector}
  1305. PROCEDURE TFontListView.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
  1306.                                                  fieldType: INTEGER)); OVERRIDE;
  1307.  
  1308.     BEGIN
  1309.     DoToField('TFontListView', NIL, bClass);
  1310.     DoToField('fFontList', @fFontList, bPointer);
  1311.     INHERITED Fields(DoToField);
  1312.     END;
  1313. {$ENDC qInspector}
  1314.  
  1315.  
  1316. {###############################################################################
  1317. TSizeListView
  1318. ###############################################################################}
  1319.  
  1320. {------------------------------------------------------------------------------}
  1321. {$S ACharDlg}
  1322. FUNCTION TSizeListView.GetItemSize(
  1323.                         anItem:             INTEGER)
  1324.                         :INTEGER;
  1325.  
  1326.     VAR
  1327.         i:                INTEGER;
  1328.         noOfSizes:        INTEGER;
  1329.         theFond:        FondHandle;
  1330.  
  1331.     BEGIN
  1332.     theFond := FondHandle(GetResource('FOND', fFondID));
  1333.     
  1334.     noOfSizes := 0;
  1335.     FOR i := 0 TO theFond^^.noOfFonts DO
  1336.         BEGIN
  1337.         IF theFond^^.fontStuff[i].style = 0 THEN
  1338.             noOfSizes := noOfSizes + 1;
  1339.             
  1340.         IF noOfSizes = anItem THEN
  1341.             BEGIN
  1342.             GetItemSize := theFond^^.fontStuff[i].size;
  1343.             EXIT(GetItemSize);
  1344.             END;
  1345.         END;
  1346.         
  1347.     GetItemSize := 0;
  1348.     END; {GetItemSize}
  1349.  
  1350. {------------------------------------------------------------------------------}
  1351. {$S ACharDlg}
  1352. FUNCTION TSizeListView.FindSizeItem(
  1353.                         theSize:             INTEGER)
  1354.                         :INTEGER;
  1355.     VAR
  1356.         i:    INTEGER;
  1357.         
  1358.     BEGIN
  1359.     FOR i := 1 TO fNumOfRows DO
  1360.         BEGIN
  1361.         IF theSize=GetItemSize(i)
  1362.         THEN
  1363.             BEGIN
  1364.             FindSizeItem := i;
  1365.             EXIT(FindSizeItem)
  1366.             END;
  1367.         END;  { for }
  1368.         
  1369.     FindSizeItem := 0;
  1370.     END; {FindSizeItem}
  1371.     
  1372. {------------------------------------------------------------------------------}
  1373. {$S ACharDlg}
  1374. FUNCTION TSizeListView.GetTextSize
  1375.                         :INTEGER;
  1376.     BEGIN
  1377.     GetTextSize := GetItemSize(LastSelectedItem) 
  1378.     END;
  1379.  
  1380. {------------------------------------------------------------------------------}
  1381. {$S ACharDlg}
  1382. PROCEDURE TSizeListView.SetTextSize(
  1383.                         theSize:            INTEGER;
  1384.                         redraw:                BOOLEAN);
  1385.  
  1386.     VAR
  1387.         anItem:    INTEGER;
  1388.         
  1389.     BEGIN
  1390.     IF (GetTextSize <> theSize)
  1391.     THEN
  1392.         BEGIN
  1393.         anItem := FindSizeItem(theSize);
  1394.         
  1395.         IF anItem <> 0 
  1396.         THEN
  1397.             INHERITED SelectItem(anItem, kDontExtend, kHighlight, kSelect);
  1398.         END;
  1399.     END;
  1400.         
  1401. {------------------------------------------------------------------------------}
  1402. {$S ACharDlg}
  1403. PROCEDURE TSizeListView.GetItemText(
  1404.                         anItem:             INTEGER;
  1405.                         VAR aString:         Str255);
  1406.                         OVERRIDE;
  1407.     BEGIN
  1408.     NumToString(GetItemSize(anItem), aString);
  1409.     END;
  1410.  
  1411. {------------------------------------------------------------------------------}
  1412. {$S ACharDlg}
  1413. PROCEDURE TSizeListView.SetNumberOfItems(
  1414.                             aNumber:             INTEGER);
  1415.  
  1416.     BEGIN
  1417.     IF fNumOfRows > aNumber
  1418.     THEN
  1419.         DelItemFirst(fNumOfRows - aNumber)
  1420.     ELSE IF fNumOfRows < aNumber
  1421.     THEN
  1422.         InsItemFirst(aNumber - fNumOfRows);
  1423.     END;
  1424.  
  1425. {------------------------------------------------------------------------------}
  1426. {$S AOpen}
  1427. PROCEDURE TSizeListView.InstallFontFamily(
  1428.                         theFondID:             INTEGER);
  1429.  
  1430.     VAR
  1431.         theFond:            FondHandle;
  1432.         noOfSizes:            INTEGER;
  1433.         i:                    INTEGER;
  1434.  
  1435.     BEGIN
  1436.     theFond := FondHandle(GetResource('FOND', theFondID));
  1437.     
  1438.     noOfSizes := 0;
  1439.     FOR i := 0 TO theFond^^.noOfFonts DO
  1440.         BEGIN
  1441.         IF theFond^^.fontStuff[i].style = 0
  1442.         THEN
  1443.             noOfSizes := noOfSizes + 1;
  1444.         END;  { for }
  1445.             
  1446.     fFondID := theFondID;
  1447.     SetNumberOfItems(noOfSizes);
  1448.     ForceRedraw;
  1449.     END;
  1450.  
  1451. {------------------------------------------------------------------------------}
  1452. {$S ACharDlg}
  1453. PROCEDURE TSizeListView.SelectItem(
  1454.                         anItem:             INTEGER;
  1455.                         extendSelection:     BOOLEAN;
  1456.                         highlight:             BOOLEAN;
  1457.                         select:             BOOLEAN);
  1458.     BEGIN
  1459.     { if anItem is 0, row 1 is selected }
  1460.     INHERITED SelectItem(anItem, extendSelection, highlight, select);
  1461.     
  1462.     IF select & (anItem <> 0)
  1463.     THEN
  1464.         DoChoice(SELF, mListFontSizeChanged);
  1465.     END;
  1466.  
  1467. {------------------------------------------------------------------------------}
  1468. {$S AFields}
  1469. PROCEDURE TSizeListView.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
  1470.                                                  fieldType: INTEGER)); OVERRIDE;
  1471.  
  1472.     BEGIN
  1473.     DoToField('TSizeListView', NIL, bClass);
  1474.     DoToField('fFondID', @fFondID, bInteger);
  1475.     INHERITED Fields(DoToField);
  1476.     END;
  1477.  
  1478.  
  1479. {###############################################################################
  1480. TSizeText
  1481. ###############################################################################}
  1482.  
  1483. {------------------------------------------------------------------------------}
  1484. {$S ACharDlg}
  1485. FUNCTION TSizeText.GetTextSize
  1486.                         :INTEGER;
  1487.     BEGIN
  1488.     GetTextSize := GetValue
  1489.     END; {GetTextSize}
  1490.     
  1491. {------------------------------------------------------------------------------}
  1492. {$S ACharDlg}
  1493. PROCEDURE TSizeText.SetTextSize(
  1494.                         theSize:            INTEGER;
  1495.                         redraw:                BOOLEAN);
  1496.     BEGIN
  1497.     SetValue(theSize,redraw);
  1498.     TDialogView(GetDialogView).DoSelectEditText(SELF, TRUE)
  1499.     END; {SetTextSize}
  1500.         
  1501. {------------------------------------------------------------------------------}
  1502. {$S ACharDlg}
  1503. FUNCTION TSizeText.Validate: LONGINT;
  1504.                         OVERRIDE;
  1505.     VAR
  1506.         result:        LONGINT;
  1507.     
  1508.     BEGIN
  1509.     result := INHERITED Validate;
  1510.     
  1511.     IF (result = kValidValue)
  1512.     THEN
  1513.         DoChoice(SELF, mTextFontSizeChanged);
  1514.         
  1515.     Validate := result;
  1516.     END;
  1517.     
  1518.     
  1519. {###############################################################################
  1520. TSizeCluster
  1521. ###############################################################################}
  1522.  
  1523. {------------------------------------------------------------------------------}
  1524. {$S AOpen}
  1525.  
  1526. { PostRes(): Initialize the dialog's subview references. }
  1527. PROCEDURE TSizeCluster.PostRes;
  1528.                         OVERRIDE;
  1529.     VAR
  1530.         aView:             TView;
  1531.  
  1532.     BEGIN
  1533.     INHERITED PostRes;
  1534.     
  1535.     aView := GetDialogView.FindSubView('size');
  1536.     FailNil(aView);
  1537.     fSizeText := TSizeText(aView); 
  1538.     
  1539.     aView := FindSubView('slst');
  1540.     FailNil(aView);
  1541.     fSizeListView := TSizeListView(aView); 
  1542.     END;  { PostRes }
  1543.  
  1544. {------------------------------------------------------------------------------}
  1545. {$S ACharDlg}
  1546. FUNCTION TSizeCluster.GetTextSize
  1547.                         :INTEGER;
  1548.     BEGIN
  1549.     GetTextSize := fSizeText.GetTextSize
  1550.     END; {GetTextSize}
  1551.  
  1552. {------------------------------------------------------------------------------}
  1553. {$S ACharDlg}
  1554. PROCEDURE TSizeCluster.SetTextSize(
  1555.                         theSize:            INTEGER;
  1556.                         redraw:                BOOLEAN);
  1557.  
  1558.     BEGIN
  1559.     fSizeText.SetTextSize(theSize,redraw);
  1560.     fSizeListView.SetTextSize(theSize,redraw)
  1561.     END;
  1562.  
  1563. {------------------------------------------------------------------------------}
  1564. {$S ACharDlg}
  1565. PROCEDURE TSizeCluster.SetTextFont(
  1566.                         theFont:            INTEGER;
  1567.                         redraw:                BOOLEAN);
  1568.     BEGIN
  1569.     fSizeListView.InstallFontFamily(theFont);
  1570.     fSizeListView.SetTextSize(GetTextSize,redraw)
  1571.     END;
  1572.         
  1573. {------------------------------------------------------------------------------}
  1574. {$S ACharDlg}
  1575. PROCEDURE TSizeCluster.DoChoice(
  1576.                         origView:            TView;
  1577.                         itsChoice:            INTEGER);
  1578.     BEGIN
  1579.     CASE itsChoice OF
  1580.         mTextFontSizeChanged:
  1581.             BEGIN
  1582.             {$IFC qDebug}
  1583.             Assertion(Member(origView, TSizeText), AtStr('Member(origView, TSizeText)'));
  1584.             {$ENDC qDebug}
  1585.             
  1586.             fSizeListView.SetTextSize(TSizeText(origView).GetTextSize, kRedraw);
  1587.             INHERITED DoChoice(origView, mFontSizeChanged);
  1588.             END;  { mTextFontSizeChanged }
  1589.         
  1590.         mListFontSizeChanged:
  1591.             BEGIN
  1592.             {$IFC qDebug}
  1593.             Assertion(Member(origView, TSizeListView), AtStr('Member(origView, TSizeListView)'));
  1594.             {$ENDC qDebug}
  1595.             
  1596.             fSizeText.SetTextSize(TSizeListView(origView).GetTextSize, kRedraw);
  1597.             INHERITED DoChoice(origView, mFontSizeChanged);
  1598.             END;  { mListFontSizeChanged }
  1599.         
  1600.         mFontSizeChanged:
  1601.             BEGIN
  1602.             {$IFC qDebug}
  1603.             ProgramBreak('In TSizeCluster.DoChoice(), unexpected ''mFontSizeChanged'' recieved.');
  1604.             {$ENDC qDebug}
  1605.             
  1606.             INHERITED DoChoice(origView, itsChoice);
  1607.             END;  { mListFontSizeChanged }
  1608.         
  1609.         OTHERWISE
  1610.             INHERITED DoChoice(origView, itsChoice);
  1611.         END; {CASE}
  1612.     END; {DoChoice}
  1613.  
  1614.  
  1615. {###############################################################################
  1616. TCharacterDialogCmd
  1617. ###############################################################################}
  1618.  
  1619. {——————————————————————————————————————————————————————————————————————————————}
  1620. {$S ASelCommand}    
  1621.  
  1622. PROCEDURE TCharacterDialogCmd.ICharacterDialogCmd(
  1623.                         itsCmdNumber:        CmdNumber;
  1624.                         itsDocument:        TDocument;
  1625.                         itsView:            TView;
  1626.                         itsScroller:        TScroller;
  1627.                         itsTextStyle:        TextStyle;
  1628.                         itsAlignment:        INTEGER);
  1629.     
  1630.     BEGIN
  1631.     IMacAppDialogCmd(
  1632.         itsCmdNumber,
  1633.         itsDocument,
  1634.         itsView,
  1635.         itsScroller,
  1636.         itsCmdNumber,        { a handy convention: 'view' rsrc ID <=> CmdNumber }
  1637.         'DLOG');
  1638.     
  1639.     fTextStyle := itsTextStyle;
  1640.     fAlignment := itsAlignment;
  1641.     END;  { ICharacterDialogCmd }
  1642.     
  1643. {——————————————————————————————————————————————————————————————————————————————}
  1644. {$S ADoCommand}
  1645.         
  1646. { InitTheDialog(): Initializes the dialog to reflect the command's
  1647.   TextStyle and alignment values. }
  1648. PROCEDURE TCharacterDialogCmd.InitTheDialog;
  1649.                         OVERRIDE;
  1650.     VAR
  1651.         theTextStyle:    TextStyle;
  1652.     
  1653.     BEGIN
  1654.     { localize to avoid unsafe field use }
  1655.     theTextStyle := fTextStyle;
  1656.     
  1657.     { initialize the dialog to act on the command's TextStyle and alignment }
  1658.     TCharDialogView(fTheDialog).SetDialogInfo(theTextStyle, fAlignment, kRedraw);
  1659.     
  1660.     { make sure the 'size' field is the current edit text item }
  1661.     fTheDialog.SelectEditText('size', TRUE);    { TRUE = DO select the text }
  1662.     END;  { InitTheDialog }
  1663.     
  1664. {——————————————————————————————————————————————————————————————————————————————}
  1665. {$S AFields}
  1666.                 
  1667. {$IFC qInspector}
  1668. PROCEDURE TCharacterDialogCmd.Fields(
  1669.                         PROCEDURE DoToField(
  1670.                             fieldName:        Str255;
  1671.                             fieldAddr:        Ptr;
  1672.                             fieldType:        INTEGER));
  1673.                         OVERRIDE;
  1674.     BEGIN
  1675.     DoToField('TCharacterDialogCmd', NIL, bClass);
  1676.     
  1677.     {$Push} {$H-}
  1678.     TextStyleFields('fTextStyle', fTextStyle, DoToField);
  1679.     {$Pop}
  1680.     DoToField('fAlignment',     @fAlignment,     bInteger);
  1681.     
  1682.     INHERITED Fields(DoToField);
  1683.     END;  { Fields }
  1684. {$ENDC qDebug}
  1685.     
  1686.     
  1687. {###############################################################################
  1688. TColorDialogCmd
  1689. ###############################################################################}
  1690.  
  1691. {——————————————————————————————————————————————————————————————————————————————}
  1692. {$S ASelCommand}
  1693.     
  1694. PROCEDURE TColorDialogCmd.IColorDialogCmd(
  1695.                         itsCmdNumber:        CmdNumber;
  1696.                         itsDocument:        TDocument;
  1697.                         itsView:            TView;
  1698.                         itsScroller:        TScroller;
  1699.                         itsInitialColor:    RGBColor;
  1700.                         itsPromptID:        INTEGER);
  1701.     BEGIN
  1702.     IToolboxDialogCmd(
  1703.         itsCmdNumber,
  1704.         itsDocument,
  1705.         itsView,
  1706.         itsScroller,
  1707.         -1,                        { this value wil be ignored  }
  1708.         [],                        { this value wil be ignored  }
  1709.         NIL);                    { this value wil be ignored  }
  1710.     
  1711.     fInitialColor := itsInitialColor;
  1712.     fResultColor  := itsInitialColor;
  1713.     fPromptID      := itsPromptID;
  1714.     END;  { IColorDialogCmd }
  1715.  
  1716. {——————————————————————————————————————————————————————————————————————————————}
  1717. {$S ADoCommand}
  1718.         
  1719. PROCEDURE TColorDialogCmd.PoseTheDialog;
  1720.                         OVERRIDE;
  1721.     VAR
  1722.         pickerPrompt:    StringHandle;
  1723.         cancelled:        BOOLEAN;
  1724.         initialColor:    RGBColor;
  1725.         resultColor:    RGBColor;
  1726.     
  1727.     BEGIN
  1728.     pickerPrompt := GetString(fPromptID);
  1729.     FailNil(pickerPrompt);
  1730.     
  1731.     { localize — That Amazing Moving Memory! }
  1732.     initialColor := fInitialColor;
  1733.     
  1734.     cancelled := NOT GetColor(gZeroPt, pickerPrompt^^, initialColor, resultColor);
  1735.     fResultColor := resultColor;
  1736.     
  1737.     SetCancelled(cancelled);
  1738.     
  1739.     IF cancelled
  1740.     THEN
  1741.         SetDismisser(cancel)
  1742.     ELSE
  1743.         SetDismisser(ok);
  1744.     END;  { PoseTheDialog }
  1745.     
  1746. {——————————————————————————————————————————————————————————————————————————————}
  1747. {$S AFields}
  1748.                         
  1749. {$IFC qInspector}
  1750. PROCEDURE TColorDialogCmd.Fields(
  1751.                         PROCEDURE DoToField(
  1752.                             fieldName:        Str255;
  1753.                             fieldAddr:        Ptr;
  1754.                             fieldType:        INTEGER));
  1755.                         OVERRIDE;
  1756.     BEGIN
  1757.     DoToField('TColorDialogCmd', NIL, bClass);
  1758.     
  1759.     DoToField('fInitialColor',     @fInitialColor,     bRGBColor);
  1760.     DoToField('fResultColor',     @fResultColor,         bRGBColor);
  1761.     
  1762.     INHERITED Fields(DoToField);
  1763.     END;  { Fields }
  1764. {$ENDC qDebug}
  1765.     
  1766. {——————————————————————————————————————————————————————————————————————————————}
  1767.